<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div id="edit_iframe" class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">员工编号</label>
        <div class="layui-input-block">
            <input id="empno" type="text" name="empno" lay-verify="required" class="layui-input" readonly="readonly">
            <tip>已注册编号不可更改</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">员工姓名</label>
        <div class="layui-input-block">
            <input id="ename" type="text" name="ename" lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">性别</label>
        <div id="sex" class="layui-input-block" >
            <input type="radio" name="sex" value="男" title="男">
            <input type="radio" name="sex" value="女" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">职位</label>
        <div class="layui-input-block">
            <select id="job" name="job">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">验证身份证</label>
        <div class="layui-input-block">
            <input id="idcard" type="text" name="idcard" lay-verify="identity" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">联系方式</label>
        <div class="layui-input-block">
            <input id="phone" type="number" name="phone" lay-verify="required" lay-reqtext="手机号不能为空"  class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">入职日期</label>
        <div class="layui-input-block">
            <input type="text" name="hiredate" id="hiredate"  lay-verify="date" placeholder="yyyy-MM-dd"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">领导编号</label>
        <div class="layui-input-block">
            <input id="mgr" type="number" name="mgr" lay-verify="required"  placeholder="请输入领导编号"  class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">月薪</label>
        <div class="layui-input-block">
            <input id="sal" type="number" name="sal" lay-verify="required"  placeholder="请输入薪资"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">奖金</label>
        <div class="layui-input-block">
            <input id="comm" type="number" name="comm" lay-verify="required"  placeholder="请输入奖金"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">所属部门</label>
        <div class="layui-input-block">
            <select id="dept" name="dept">
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$,
            laydate = layui.laydate;

        //日期
        var date= new Date();
        var day = ("0" + date.getDate()).slice(-2);
        var month = ("0" + (date.getMonth() + 1)).slice(-2);
        var today= date.getFullYear() + "-" + (month) + "-" + (day);
        $('#hiredate').val(today);
        laydate.render({
            elem: '#hiredate'
        });

        function job_Post(callback) {
            $.ajax({
                method: "POST",
                url:"/role/list",
                success: function (result) {
                    $.post(
                        "/param/empedit",{empno:$("#empno").val()},
                        function (data) {
                            if (!result.IsError) {
                                for (var num=0;num<result.length;num++){
                                    if (data[0].roles.rid==result[num].rid){
                                        $('#job').append(new Option(text= result[num].role,value=result[num].rid,defaultSelected="true",selected="selected"));
                                    }else {
                                        $('#job').append(new Option(text= result[num].role,value=result[num].rid));
                                    }
                                }
                                layui.form.render();
                                if (typeof callback === "function") {
                                    callback();
                                }
                            }
                            else {
                                layer.msg(result.Message);
                            }
                        },"JSON"
                    )
                },
                dataType:"JSON",
                error: function (error) {
                    layer.msg("服务器错误！");
                }
            });
        }

        function dept_Post(callback) {
            $.ajax({
                method: "POST",
                url:"/dept/list",
                success: function (result) {
                    $.post(
                        "/param/empedit",{empno:$("#empno").val()},
                        function (data) {
                    if (!result.IsError) {
                        for (var num=0;num<result.length;num++){
                            if (data[0].deptnos.deptno==result[num].deptno){
                                $('#dept').append(new Option(text = result[num].dname, value = result[num].deptno,defaultSelected="true",selected="selected"));
                            }else {
                                $('#dept').append(new Option(text = result[num].dname, value = result[num].deptno));
                            }
                        }
                        layui.form.render();
                        if (typeof callback === "function") {
                            callback();
                        }
                    }
                    else {
                        layer.msg(result.Message);
                    }
                        },"JSON"
                    )
                },
                dataType:"JSON",
                error: function (error) {
                    layer.msg("服务器错误！");
                }
            });
        }
        job_Post();
        dept_Post();


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = JSON.stringify(data.field)
            $.post(
                "/emp/edit",{
                    emplist:JSON.stringify(data.field)
                },function () {
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
                }
            )

            return false;
        });

    });
</script>
</body>
</html>